#include <stdio.h>
#include <string.h>

struct Book {
    char name[31];
    double price;
};

int main() {
    int n;
    scanf("%d", &n);
    struct Book books[10];
    for (int i = 0; i < n; i++) {
        getchar();
        fgets(books[i].name, 31, stdin);
        int len = strlen(books[i].name);
        if (books[i].name[len - 1] == '\n') books[i].name[len - 1] = '\0';
        scanf("%lf", &books[i].price);
    }
    int maxIdx = 0, minIdx = 0;
    for (int i = 1; i < n; i++) {
        if (books[i].price > books[maxIdx].price) maxIdx = i;
        if (books[i].price < books[minIdx].price) minIdx = i;
    }
    printf("%.2f, %s\n", books[maxIdx].price, books[maxIdx].name);
    printf("%.2f, %s\n", books[minIdx].price, books[minIdx].name);
    return 0;
}
